package cn.fsd.util;

import java.util.Calendar;
import java.util.Date;
import java.util.Objects;
import org.apache.commons.lang.time.DateUtils;

public class TaskDate extends Date {

  public TaskDate(Date date){
    super(date.getTime());
  }

  @Override
  public boolean equals(Object obj) {
    return obj instanceof Date && DateUtils.isSameDay(this,(Date)obj);
  }

  @Override
  public int hashCode(){
    return Objects.hash(getYear(this),getMonth(this),getDay(this));
  }

  public int getYear(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    return calendar.get(Calendar.YEAR);
  }

  public int getMonth(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    return calendar.get(Calendar.MONTH) + 1; // 月份从0开始，需要加1
  }

  public int getDay(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    return calendar.get(Calendar.DAY_OF_MONTH);
  }
}
